#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File    ：agent.py
@Author  ：平
@Date    ：2025/9/28 17:00 
"""
from typing import Union, Dict

from langchain_core.language_models import BaseChatModel
from langgraph.graph.state import CompiledStateGraph
from langgraph.prebuilt import create_react_agent

from app.graph.llm import get_llm


def get_agent(name: str, llm: BaseChatModel = None, tools: list = None,
              response_format: Union[Dict, type] = None, **kwargs) -> CompiledStateGraph:
    """
    获取智能体
    Args:
        name: 智能体名称
        llm: 大模型
        tools: 工具
        response_format: 结构化输出
        **kwargs: 额外配置

    Returns: 智能体
    """
    tools = [] if tools is None else tools
    final_llm = llm or get_llm()
    if response_format:
        return create_react_agent(final_llm, name=name, tools=tools, response_format=response_format, **kwargs)
    return create_react_agent(final_llm, name=name, tools=tools, **kwargs)
